package com.dgut.Utils;


import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Base64;
import java.util.Base64.Encoder;

/**
 * @author GooRay
 * 创建于 2020/6/13
 */
public class DownLoadUtils {
    public static String getFileName(String agent, String filename) throws UnsupportedEncodingException {
        if(agent.contains("MSIE")){
            //IE浏览器
            filename = URLEncoder.encode(filename,"utf-8");
            filename = filename.replace("+"," ");
        }else if(agent.contains("Firefox")){
            //火狐浏览器
            Encoder encoder = Base64.getEncoder();
            filename = "=?utf-8?B?" + encoder.encode(filename.getBytes("utf-8"))+ "?=";
        }else{
            filename = URLEncoder.encode(filename,"utf-8");
        }
        return filename;
    }
}
